#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 64100;
const int M = 5e5+10;
const int inf = 0x3f3f3f3f;

int h[N],S,T,v[45][45][45],P,Q,R,D,cnt=1,maxflow,d[N],now[N],h1[4] = {0,0,1,-1},h2[4] = {1,-1,0,0};
struct edge{int v,w,nxt;}e[M<<1];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;e[++cnt] = (edge){x,0,h[y]};h[y] = cnt;}
int id(int x,int y,int z){return (x - 1) * P * Q + (y - 1) * Q + z;}

bool bfs(){
	queue<int> q;q.push(S); memset(d,0,sizeof(d)); d[S] = 1; now[S] = h[S];
	while(q.size()){
		int x = q.front();q.pop();
		for(int i = h[x],y;i;i = e[i].nxt){
			if(!d[y = e[i].v] && e[i].w){
				d[y] = d[x] + 1; now[y] = h[y];
				q.push(y); if(y == T) return 1;
			}
		}
	}return 0;
}

int dfs(int x,int flow){
	if(x == T) return flow; int res = flow;
	for(int i = now[x],y;i&&res;i = e[i].nxt){
		now[x] = i;
		if(d[y = e[i].v] == d[x] + 1 && e[i].w){
			int k = dfs(y,min(res,e[i].w));
			if(!k) d[y] = 0; res -= k; e[i].w -= k; e[i^1].w += k;
		}
	}return flow - res;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	P = in,Q = in,R = in; D = in;
	for(int k = 1;k <= R;k++)
		for(int i = 1;i <= P;i++)
			for(int j = 1;j <= Q;j++)
				v[i][j][k] = in;
	S = 0; T = P * Q * (R+1) + 2;
	for(int i = 1;i <= P;i++)
		for(int j = 1;j <= Q;j++){
			for(int k = 1;k <= R+1;k++){
				int now = id(k,i,j);
				if(k <= R) link(now,id(k+1,i,j),v[i][j][k]);
				if(k == 1) link(S,now,inf);
				if(k > D){
					for(int d = 0;d < 4;d++){
						int nx = i + h1[d],ny = j + h2[d];
						if(nx < 1 || ny < 1 || nx > P || ny > Q) continue;
						link(now,id(k-D,nx,ny),inf);
					}
				}
				if(k == R+1) link(now,T,inf);
			}
		}
	int flow = 0;while(bfs()) while(flow = dfs(S,inf)) maxflow += flow;
	printf("%d\n",maxflow);
	return 0;
}
